﻿/*!
 *
 * Date: 31/05/2011
 * NEWSLETTER GENERATOR 
 * http://pukis.com.br/
 *
 * Copyright 2011, Felipe Assunção | felipeassuncao.net[at]gmail.com
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 *
 * Require jQuery JavaScript Library v1.4 or Newest
 * http://jquery.com/
 * Copyright 2011, John Resig
 * Released under the MIT and GPL Licenses.
 * 
 */
	// Variable responsable of alocate the newsletter configs.
	xhtmlConfigs = []; // width, name, charset
	// Variable responsable of alocate the newsletter content.
	xhtmlRows = [];
	// Variable used to restore the string.
	xhtmlRowsRestore = [];
	// Variable used to mount the array.
	mountString = [];
	// Function responsable of add a new row on the newsletter.
	function addItem(type,values) {
		mountString = [];
		// When the user has added a image.
		if ( type == 'image' ){
			//adding the parameter on the string to mount a new array
			mountString.push(type);
			// Travelsing the parameters.
			for( i = 0;  i <= ( values.length - 1 ); i++) { // the length has decreased by 1 because of the array beguns in 0;
				// Building the array.
				mountString.push(values[i]);
			};
			//adding the image parameters to the plugin
			xhtmlRows.push(mountString);
			//console.log(xhtmlRows);
		
		}
		// When the user has added a text.
		else if ( type == 'text' ) {
		
			//adding the parameter on the string to mount a new array
			mountString.push(type);
			// Travelsing the parameters.
			for( i = 0;  i <= ( values.length - 1 ); i++) { // the length has decreased by 1 because of the array beguns in 0;
				// Building the array.
				mountString.push(values[i]);
			};
			//adding the image parameters to the plugin
			xhtmlRows.push(mountString);
			//console.log(xhtmlRows);
		
		}
		// When the user has added a product.
		else if ( type == 'product' ) {
		
			//adding the parameter on the string to mount a new array
			mountString.push(type);
			// Travelsing the parameters.
			for( i = 0;  i <= ( values.length - 1 ); i++) { // the length has decreased by 1 because of the array beguns in 0;
				// Building the array.
				mountString.push(values[i]);
			};
			//adding the image parameters to the plugin
			xhtmlRows.push(mountString);
			//console.log(xhtmlRows);
		
		}
		// Se os parametros não se adequarem as condições acima, o parametro passado não segue as caracteristicas
	}
	
	
	// function responsable of remove thr row from the array
	function removeRow(index){
	
		xhtmlRows.remove(index,1);
        console.log(index)
	
	}
	
	function updateRow(index,vector){
	
		xhtmlRows.insert(index,vector);
		
	}
	
	// Função responsável por gerar o Conteúdo XHTML após a conclusão da newsletter.	
	function generatexhtml() {
	
		console.log(xhtmlRows);
			
	}

	Array.prototype.remove = function(start, end) {
		this.splice(start, end);
		return this;
	}

	Array.prototype.insert = function(pos, item) {
		this.splice(pos, 1, item);
		return this;
	}
